package qdrant

import (
	"log"
)

// QdrantClient 定义Qdrant客户端接口
type QdrantClient interface {
	// 初始化和连接
	Initialize(config *Config) error
	Close() error
	HealthCheck() error

	// 向量操作
	InsertVectors(vectors []Vector) error
	SearchVectors(query Vector, limit int) ([]SearchResult, error)
	DeleteVectors(ids []string) error

	// 集合管理
	CreateCollection(name string, config CollectionConfig) error
	DeleteCollection(name string) error
	GetCollectionInfo(name string) (*CollectionInfo, error)
}

// Vector 表示一个向量及其元数据
type Vector struct {
	ID      string                 `json:"id"`
	Vector  []float32              `json:"vector"`
	Payload map[string]interface{} `json:"payload"`
}

// SearchResult 表示搜索结果
type SearchResult struct {
	ID      string                 `json:"id"`
	Score   float32                `json:"score"`
	Payload map[string]interface{} `json:"payload"`
}

// CollectionConfig 表示集合配置
type CollectionConfig struct {
	VectorSize int    `json:"vector_size"`
	Distance   string `json:"distance"`
}

// CollectionInfo 表示集合信息
type CollectionInfo struct {
	Name        string `json:"name"`
	VectorCount int64  `json:"vector_count"`
	Status      string `json:"status"`
}

// VectorClient 实现QdrantClient接口，使用SimpleQdrantClient
type VectorClient struct {
	simpleClient *SimpleQdrantClient
}

// NewVectorClient 创建一个新的向量客户端
func NewVectorClient() *VectorClient {
	return &VectorClient{
		simpleClient: NewSimpleQdrantClient(),
	}
}

// Initialize 初始化客户端连接
func (vc *VectorClient) Initialize(config *Config) error {
	log.Printf("Initializing VectorClient with SimpleQdrantClient")
	return vc.simpleClient.Initialize(config)
}

// Close 关闭客户端连接
func (vc *VectorClient) Close() error {
	return vc.simpleClient.Close()
}

// HealthCheck 执行健康检查
func (vc *VectorClient) HealthCheck() error {
	return vc.simpleClient.HealthCheck()
}

// InsertVectors 批量插入向量
func (vc *VectorClient) InsertVectors(vectors []Vector) error {
	return vc.simpleClient.InsertVectors(vectors)
}

// SearchVectors 搜索相似向量
func (vc *VectorClient) SearchVectors(query Vector, limit int) ([]SearchResult, error) {
	return vc.simpleClient.SearchVectors(query, limit)
}

// DeleteVectors 删除向量
func (vc *VectorClient) DeleteVectors(ids []string) error {
	return vc.simpleClient.DeleteVectors(ids)
}

// CreateCollection 创建集合
func (vc *VectorClient) CreateCollection(name string, config CollectionConfig) error {
	return vc.simpleClient.CreateCollection(name, config)
}

// DeleteCollection 删除集合
func (vc *VectorClient) DeleteCollection(name string) error {
	return vc.simpleClient.DeleteCollection(name)
}

// GetCollectionInfo 获取集合信息
func (vc *VectorClient) GetCollectionInfo(name string) (*CollectionInfo, error) {
	return vc.simpleClient.GetCollectionInfo(name)
}
